﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VectorHelper;

namespace 向量测试二
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private const float m_x = 250, m_y = 270, m_r = 10;
        private float m_rete = 5;
        private Vector M = new Vector(300, 250);
        private Vector m = new Vector(m_x, m_y);

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            using (Pen p = new Pen(Color.Green))
            {
                Graphics g = this.panel1.CreateGraphics();
                g.DrawLine(p, new PointF(0, 0), new PointF(M.X, M.Y));
            }
            PaintCirle(M, 1, Color.Green);
            PaintCirle(M, 200, Color.Green);
            PaintCirle(m, m_r, Color.Red);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //删掉旧小圆
            //PaintCirle(m, m_r, Color.Black);
            //画新的小圆 
            //PaintCirle(Func.Move(m, m_rete), m_r, Color.Red);
            var new_m = Func.Move(m, m_rete);
            using (Pen p = new Pen(Color.Green))
            {
                Graphics g = this.panel1.CreateGraphics();
                g.DrawLine(p, new PointF(0, 0), new PointF(new_m.X, new_m.Y));
            }

            //重画大圆，避免覆盖
            PaintCirle(M, 200, Color.Green);
            label1.Text = (Func.GetAngle(M, m)).ToString();
        }


        /// <summary>
        /// 画圆
        /// </summary>
        /// <param name="vector"></param>
        /// <param name="r"></param>
        /// <param name="color"></param>
        private void PaintCirle(Vector vector, float r, Color color)
        {
            using (Pen p = new Pen(color))
            {
                Graphics g = this.panel1.CreateGraphics();
                g.DrawEllipse(p, vector.X - r, vector.Y - r, r * 2, r * 2);
            }
        }

    }
}
